from django.contrib import admin

# Register your models here.
from student import models


class StudentAdmin(admin.ModelAdmin):
    list_display = ('name', 'status', 'alias', 'height', 'weight')


def upper_comment(obj):
    """被list_display应用的方法，要写在类的外面"""
    return obj.comment.upper()
upper_comment.short_description = '大写comment'


class PersonAdmin(admin.ModelAdmin):
    list_display = ('name', 'id', 'gender', 'age', 'universe', 'bounty', 'comment', upper_comment)
    list_filter = ('gender', 'universe')
    search_fields = ('name', 'comment')
    list_per_page = 10
    readonly_fields = ('comment_link',)

    def comment_link(self, instance):
        """演示一下自定义的只读字段"""
        return '-'.join(line.upper() for line in instance.comment)
    comment_link.short_description = "comment_大写分割"


class TagAdmin(admin.ModelAdmin):
    list_display = ('name', 'date')


admin.site.register(models.Person, PersonAdmin)
admin.site.register(models.Student, StudentAdmin)
admin.site.register(models.Tag, TagAdmin)

